package ui.adapter;

import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.fy.fyzf.R;
import com.fy.fyzf.bean.SignDetailBean;
import com.fy.fyzf.utils.AppUtils;

import java.util.ArrayList;
import java.util.List;

public class FenPeiInfoAdapter extends BaseQuickAdapter<SignDetailBean.PerformanceUserDetailsVosBean, BaseViewHolder> {

    private int mType; // 1 签约第三步  2 签约详情
    public FenPeiInfoAdapter(int i) {
        super(R.layout.item_allowcation_info);
        mType = i;
    }

//    private List<SignDetailBean.PerformanceUserDetailsVosBean> data = new ArrayList<>();
    public void insertItem(int i) {
        notifyItemInserted(getData().size());
        notifyItemRangeChanged(i, getData().size() - i);
    }

    public void removeItem(int i) {
        getData().remove(i);
        notifyItemRemoved(i);
        notifyDataSetChanged();
    }

    @Override
    protected void convert(BaseViewHolder helper, SignDetailBean.PerformanceUserDetailsVosBean item) {
        helper.setIsRecyclable(false);
        helper.addOnClickListener(R.id.tv_add);
        helper.getView(R.id.tv_delete).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AppUtils.showToast(""+helper.getAdapterPosition());
                if (getItemCount() > 1) {
                    removeItem(helper.getAdapterPosition());
                } else {
                    AppUtils.showToast("最少一条数据");
                }
            }
        });


        EditText etName = helper.getView(R.id.et_name);
        EditText etBaiFenBi = helper.getView(R.id.et_deal_percentage);
        EditText etYingYeE = helper.getView(R.id.et_yingye);
        EditText etCompanyName = helper.getView(R.id.et_company_name);
        EditText etReason = helper.getView(R.id.et_reason);

        if (mType == 2) {
            etName.setText(item.getAssignName());
            etBaiFenBi.setText(item.getAssignPct());
            etYingYeE.setText(item.getAssignTurnover());
            etCompanyName.setText(item.getAssignGroupName());
            etReason.setText(item.getAssignReason());
        }
        etName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setAssignName(s.toString());
            }
        });

        etBaiFenBi.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setAssignPct(s.toString());
            }
        });

        etYingYeE.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setAssignTurnover(s.toString());
            }
        });

        etCompanyName.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setAssignGroupName(s.toString());
            }
        });

        etReason.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {

            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {

            }

            @Override
            public void afterTextChanged(Editable s) {
                item.setAssignReason(s.toString());
            }
        });
    }
}
